﻿$(document).on("pageInit", "#create-timetable", function (e, id, page) {

    $.getJSON("/timetable/GetAllClazzEntity", {}, function (response) {
        //console.log(response);

        var $clazzIdSelector = $(page).find('[name="ClazzId"]');
        $clazzIdSelector.empty();
        $.each(response, function (rIndex, rItem) {
            $clazzIdSelector.append("<option value='" + rItem.ClazzId + "'>" + rItem.ClazzName + "</option>");
        });
    });


    $(page).find("[name=save-timetable-form]").on("submit", function (evt) {
        evt.preventDefault();
        $(page).find("[name=save-timetable-form]").ajaxSubmit({
            success: function (response) {
                if (response.indexOf("err:") > -1) {
                    $.toast(response.substr(4));
                    return false;
                }
                $.router.load('/timetable/courceList/' + response, true);
            }
        });
    });
});